home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 12 / Mac Magazin and MacEasy Magazine CD - Issue 12.iso / Diskette Mac MAGAZIN / QuickEditor 3.6 (FAT) / Documentation / How to write plug-ins / Examples / Video Effect / Tint.c < prev    next >
Text File  |  1995-04-17  |  8KB  |  238 lines

  1. /********************                        ***********************/
  2. //
  3. //    Tint Plug-in Source Code
  4. //
  5. //    Version 0.7d        Mathias TSCHOPP
  6. //
  7. //
  8. //    Mathias TSCHOPP
  9. //    13 Troupe
  10. //    CH-1253 Vandoeuvres
  11. //    GENEVA / SWITZERLAND
  12. //    
  13. //    FAX:                (+41 22) 348 33 28
  14. //    Internet:     mtschopp@perokcity.net.ch (only short mails, no binaries!)
  15. //                            mtz@medsun.unige.ch
  16. //
  17. /********************                        ***********************/
  18.  
  19. #include "QDOffscreen.h"
  20.  
  21. #define zGray1        { 0xFFFF, 0xFFFF, 0xFFFF }    
  22. #define zGray2        { 0xEEEE, 0xEEEE, 0xEEEE }
  23. #define zGray3        { 0xDDDD, 0xDDDD, 0xDDDD }    
  24. #define zGray4        { 0xCCCC, 0xCCCC, 0xCCCC }    
  25. #define zGray5        { 0xBBBB, 0xBBBB, 0xBBBB }
  26. #define zGray6        { 0xAAAA, 0xAAAA, 0xAAAA }    
  27. #define zGray7        { 0x9999, 0x9999, 0x9999 }    
  28. #define zGray8        { 0x8888, 0x8888, 0x8888 }    
  29. #define zGray9        { 0x7777, 0x7777, 0x7777 }    
  30. #define zGray10        { 0x6666, 0x6666, 0x6666 }    
  31. #define zGray11        { 0x5555, 0x5555, 0x5555 }    
  32. #define zGray12        { 0x4444, 0x4444, 0x4444 }    
  33. #define zGray13        { 0x3333, 0x3333, 0x3333 }    
  34. #define zGray14        { 0x2222, 0x2222, 0x2222 }    
  35. #define zGray15        { 0x1111, 0x1111, 0x1111 }
  36.  
  37. typedef struct{
  38.     short what;
  39.     Point where;
  40.     } messageType;
  41.  
  42. typedef struct{
  43.     RGBColor color;
  44.     short factor;
  45.     } **PrefHand;        // This is where local variables are gonna be stored from one call to another
  46.  
  47. // This ProcInfo descriptor is only for PPC Plug-ins, remove it if you compile for 68k.
  48.  
  49. ProcInfoType __procinfo = kCStackBased|\
  50.                     RESULT_SIZE( SIZE_CODE( sizeof(Boolean) ))|\
  51.                     STACK_ROUTINE_PARAMETER( 1, SIZE_CODE( sizeof( short)))|\
  52.                     STACK_ROUTINE_PARAMETER( 2, SIZE_CODE( sizeof( GWorldPtr)))|\
  53.                     STACK_ROUTINE_PARAMETER( 3, SIZE_CODE( sizeof( GWorldPtr)))|\
  54.                     STACK_ROUTINE_PARAMETER( 4, SIZE_CODE( sizeof( short)))|\
  55.                     STACK_ROUTINE_PARAMETER( 5, SIZE_CODE( sizeof( Rect*)))|\
  56.                     STACK_ROUTINE_PARAMETER( 6, SIZE_CODE( sizeof( messageType*)));
  57.  
  58. Boolean DoProcess(short,GWorldPtr,GWorldPtr,short,Rect *,RGBColor);
  59. void WriteRes(RGBColor,short);
  60. Boolean HiliteButton(Rect);
  61.  
  62. Boolean main (short i,GWorldPtr GMonde1,GWorldPtr GMonde2,short nbOfFrames,Rect *MoviEBox,messageType *message)
  63. {
  64.     Rect theCoo,Etal,Button,Slide,FiltScreen;
  65.     short FiltCursor,theHCoo;
  66.     CIconHandle slider;
  67.     RGBColor whiteRGB = { 0xFFFF, 0xFFFF, 0xFFFF };
  68.     RGBColor blackRGB = { 0, 0, 0 };
  69.     RGBColor BlueColor={ 0xCCCC, 0xCCCC, 0xFFFF };
  70.     GrafPtr savePort;
  71.     PrefHand PrefHandle;
  72.     RGBColor tintColor;
  73.     GWorldPtr currPort;
  74.     GDHandle currDev;
  75.     Boolean errorFlag=0;
  76.     
  77.     GetGWorld(&currPort,&currDev);    //Get current graphic port so you can restore it
  78.  
  79.     SetRect(&Etal,0,0,MoviEBox->right,MoviEBox->bottom);
  80.     SetRect(&FiltScreen,463,168,622,287);    // Video Effect screen on QuickEditor Video Effect Panel
  81.     SetRect(&Slide,321,110+147,426,119+147);// Slide
  82.     SetRect(&Button,399,24+147,447,50+147);//Color Button
  83.     slider=GetCIcon(134);
  84.     GetPort(&savePort);    // savePort now contains the address of QuickEditor Window
  85.     PrefHandle =(PrefHand) GetResource('fact',128);
  86.     FiltCursor=(**PrefHandle).factor;    // load parameters that were stored in resource into local variables
  87.     tintColor=(**PrefHandle).color;
  88.     ReleaseResource((Handle)PrefHandle);
  89.     SetGWorld(GMonde1,nil);EraseRect(&Etal);
  90.     CopyBits ( (BitMap *) (*(GMonde2->portPixMap)), (BitMap *) (*(GMonde1->portPixMap)), &Etal, &Etal, srcCopy+64, nil);
  91.     SetGWorld(currPort,currDev);                    
  92.                         
  93.     
  94.     if (message->what==-1)    {
  95.         FiltCursor=10;            // Set Default value the first time the plug-in is called
  96.         WriteRes(tintColor,FiltCursor);
  97.         }
  98.     
  99.     if (message->what==0)    {
  100.         PicHandle thePict;
  101.         Rect Coord;
  102.         // This is an update event.
  103.         // Let's draw on QuickEditor Screen
  104.         thePict=GetPicture(137);
  105.         DrawPicture(thePict,&Button);
  106.         ReleaseResource((Handle)thePict);
  107.         theHCoo=-3+321+7.5*FiltCursor;
  108.         if (theHCoo<321) theHCoo=321;
  109.         if (theHCoo>417) theHCoo=417;
  110.         SetRect(&theCoo,321,110+147,426,119+147);
  111.         RGBForeColor(&BlueColor);
  112.         PaintRect(&theCoo);
  113.         RGBForeColor(&blackRGB);
  114.         SetRect(&theCoo,theHCoo,110+147,theHCoo+9,119+147);
  115.         PlotCIcon(&theCoo,slider);
  116.         RGBForeColor(&blackRGB);RGBBackColor(&whiteRGB);
  117.         errorFlag=DoProcess(FiltCursor,GMonde1,GMonde2,nbOfFrames,&Etal,tintColor);
  118.         if (errorFlag) return 1;
  119.         CopyBits ( (BitMap *) (*(GMonde2->portPixMap)),&((GrafPtr)savePort)->portBits, &Etal, &FiltScreen, srcCopy+64, nil);
  120.         }
  121.     
  122.     if (message->what==1)    {
  123.         // Process event. Let's process the Video Effect
  124.         errorFlag=DoProcess(FiltCursor,GMonde1,GMonde2,nbOfFrames,&Etal,tintColor);
  125.         if (errorFlag) return 1;
  126.         }
  127.         
  128.     if (message->what==2)    {
  129.         if (PtInRect(message->where,&Slide)) {
  130.             Point MouseLoc,MouseLoc2={-1,-1};
  131.             // The user clicked on the slider. Let's change values and give the user visual feedback
  132.             while (StillDown()) {
  133.                 GetMouse(&MouseLoc);
  134.                     if (MouseLoc.h!=MouseLoc2.h) {
  135.                     FiltCursor=(float)(MouseLoc.h-321)/7.5;
  136.                     if (FiltCursor<0) FiltCursor=0;
  137.                     if (FiltCursor>14) FiltCursor=14;
  138.                     theHCoo=-4+MouseLoc.h;
  139.                     if (theHCoo<321) theHCoo=321;
  140.                     if (theHCoo>417) theHCoo=417;
  141.                     SetRect(&theCoo,321,110+147,426,119+147);
  142.                     RGBForeColor(&BlueColor);
  143.                     PaintRect(&theCoo);
  144.                     RGBForeColor(&blackRGB);
  145.                     SetRect(&theCoo,theHCoo,110+147,theHCoo+9,119+147);
  146.                     PlotCIcon(&theCoo,slider);
  147.                     RGBForeColor(&blackRGB);RGBBackColor(&whiteRGB);
  148.                     errorFlag=DoProcess(FiltCursor,GMonde1,GMonde2,nbOfFrames,&Etal,tintColor);
  149.                     if (errorFlag) return 1;
  150.                     CopyBits ( (BitMap *) (*(GMonde2->portPixMap)),&((GrafPtr)savePort)->portBits, &Etal, &FiltScreen, srcCopy+64, nil);
  151.                     }
  152.                 MouseLoc2=MouseLoc;
  153.                 }
  154.             }
  155.         if (PtInRect(message->where,&Button)) {
  156.             Boolean answer=0;
  157.             RGBColor theColor;
  158.             Point where={-1,-1};
  159.             // The user wants to change the color
  160.             if (HiliteButton(Button)) {
  161.                 answer=GetColor(where,"\pPick a Color:",&tintColor,&theColor);
  162.                 if (answer)    tintColor=theColor;
  163.                 }
  164.             }
  165.         // Let's not forget to write the new parameters in the resource fork so
  166.         // we can retrieve them the next time the plug-in is called
  167.         WriteRes(tintColor,FiltCursor);    
  168.         }
  169.     DisposCIcon(slider);
  170.     return 0;
  171. }
  172.  
  173. Boolean DoProcess(short i,GWorldPtr GMonde1,GWorldPtr GMonde2,short nbOfFrames,Rect *MoviEBox,RGBColor tintColor)
  174. {
  175.     RGBColor FadeGrays[15]={zGray15,zGray14,zGray13,zGray12,zGray11,zGray10,zGray9,zGray8,zGray7,zGray6,
  176.                 zGray5,zGray4,zGray3,zGray2,zGray1};
  177.     Rect Etal;
  178.     GWorldPtr GMondeMask=nil;
  179.     GWorldPtr currPort;
  180.     GDHandle currDev;
  181.     OSErr err;
  182.     RGBColor whiteRGB = { 0xFFFF, 0xFFFF, 0xFFFF };
  183.     RGBColor blackRGB = { 0, 0, 0 };
  184.     
  185.     GetGWorld(&currPort,&currDev);
  186.     SetRect(&Etal,0,0,MoviEBox->right,MoviEBox->bottom);
  187.     err = NewGWorld(&GMondeMask,32, &Etal, nil, nil, 0);
  188.     if (!GMondeMask) return 1;
  189.     SetGWorld(GMondeMask,nil);    
  190.     LockPixels (GMondeMask->portPixMap);
  191.     EraseRect(&Etal);
  192.     RGBForeColor(&FadeGrays[i]);
  193.     PaintRect(&Etal);
  194.     SetGWorld(GMonde2,nil);
  195.     EraseRect(&Etal);
  196.     RGBForeColor(&tintColor);
  197.     PaintRect(&Etal);
  198.     RGBForeColor(&blackRGB);RGBBackColor(&whiteRGB);
  199.     SetGWorld(GMonde2,nil);    
  200.     CopyMask((BitMap *) (*(GMonde1->portPixMap)),(BitMap *) (*(GMondeMask->portPixMap)),
  201.     (BitMap *) (*(GMonde2->portPixMap)),&Etal,&Etal,&Etal);
  202.     SetGWorld (currPort, currDev);
  203.     UnlockPixels(GMondeMask->portPixMap);
  204.     DisposeGWorld(GMondeMask);
  205.     return 0;
  206. }
  207.  
  208. void WriteRes(RGBColor theColor,short factor)
  209. {
  210.     PrefHand PrefHandle;
  211.     
  212.     PrefHandle =(PrefHand) GetResource('fact',128);
  213.     (**PrefHandle).color = theColor;
  214.     (**PrefHandle).factor = factor;
  215.     ChangedResource((Handle)PrefHandle);
  216.     WriteResource((Handle)PrefHandle);
  217.     ReleaseResource((Handle)PrefHandle);
  218. }
  219.  
  220. Boolean HiliteButton(Rect ButtonC)
  221. {
  222.     Point MouseLoc;
  223.     Boolean isInv=0;
  224.     
  225.     while (StillDown()) {
  226.         GetMouse(&MouseLoc);
  227.         if (PtInRect(MouseLoc,&ButtonC)&&!isInv) {
  228.             InvertRect(&ButtonC);
  229.             isInv=1;
  230.             }
  231.         if (!PtInRect(MouseLoc,&ButtonC)) {
  232.             if (isInv) InvertRect(&ButtonC);
  233.             isInv=0;
  234.             }
  235.         }
  236.     if (isInv) InvertRect(&ButtonC);
  237.     return isInv;
  238. }